from random import randint
from cProfile import Profile
from pstats import Stats


def insert_values(array, value):
    for i, existing in enumerate(array):
        if existing > value:
            array.insert(i, value)
            return
    array.append(value)


def insert_sort(data):
    ret = []
    for value in data:
        insert_values(ret, value)
    return ret


def test():
    max_size = 10 ** 4
    data = [randint(0, max_size) for _ in range(max_size)]
    test_ret = lambda: insert_sort(data)
    return test_ret


if __name__ == '__main__':
    profile = Profile()
    profile.runcall(test)

    stats = Stats(profile)
    stats.strip_dirs()
    stats.sort_stats('cumulative')
    stats.print_stats()
    stats.print_callers()

